/****************************************************
	文件：Schemes.cs
	作者：HuskyT
	邮箱：1005240602@qq.com
	日期：2020/9/26 1:52:12
	功能：配置表 管理器
*****************************************************/

using System;
using System.Collections.Generic;
using UnityEngine;
using HTUtility;

namespace RedSpotSystem
{
    public class SchemesMgr : Singleton<SchemesMgr>
    {
        private Dictionary<GEnum.E_Scheme, object> mDict;

        public void Init()
        {
            mDict = new Dictionary<GEnum.E_Scheme, object>();
            LoadSchemes();
            HTLogger.Info("SchemesMgr init done.");
        }

        /// <summary>
        /// 加载指定Scheme数据
        /// </summary>
        /// <param name="scheme">配置表</param>
        public void Load(GEnum.E_Scheme scheme)
        {
            string schemeName = Enum.GetName(typeof(GEnum.E_Scheme), scheme);
            string path = Consts.BinaryFolderPath + schemeName + ".bytes";
            object obj = HelperUtil.BinaryToObjInEditor(path);
            if (mDict.ContainsKey(scheme))
            {
                HTLogger.Error("重复加载Scheme：{0}", schemeName);
            }
            else
            {
                mDict.Add(scheme, obj);
            }
        }
        /// <summary>
        /// 获取配置表数据
        /// </summary>
        /// <param name="scheme">配置表</param>
        /// <returns></returns>
        public object Get(GEnum.E_Scheme scheme)
        {
            object obj = null;
            if (mDict.TryGetValue(scheme, out obj) == false || obj == null)
            {
                HTLogger.Error("尚未加载配置表：{0}", Enum.GetName(typeof(GEnum.E_Scheme), scheme));
                return null;
            }
            return obj;
        }
        /// <summary>
        /// 加载所有的配置表
        /// </summary>
        private void LoadSchemes()
        {
            for (int i = 1; i < (int)GEnum.E_Scheme.MAX; i++)
            {
                Load((GEnum.E_Scheme)i);
            }
        }
    }
}
